<%@ Page Language="C#" MasterPageFile="~/master/admin.master" AutoEventWireup="true"
    CodeFile="sales-ccfail.aspx.cs" Inherits="admin_sales_ccfail" Title="Sales Failed" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<asp:Content ID="cntMiddleContent" ContentPlaceHolderID="cphMiddleContent" runat="Server">
    <script type="text/javascript">

        var OrderCode_Renderer = function (value, p, record, rowIndex) {

            var categoryUrl;
            categoryUrl = String.format("<%= Page.ResolveUrl(eShop.Business.CustomSiteMap.InvoicePrintPage) %>?print=0&oid={0}", record.data.OrderId);
            categoryUrl = String.format("<a href=\"{0}\" class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl, record.data.OrderNumber + record.data.OrderId);

            return categoryUrl;
        };


        var Invoice_Renderer = function (value, p, record, rowIndex) {
            var categoryUrl;
            var urltext;
            urltext = String.format("<a class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl, "");
            return urltext;
        };




        var Date_Renderer = function (value) {
            var dt = new Date(value);
            return dt.format('m/d/Y');
        }




        var CommandHandler = function (command, rowIndex, grid) {
            //showObj(grid);

            grid.getRowEditor().stopEditing();

            grid.getView().refresh();

            grid.getSelectionModel().selectRow(rowIndex);
            
            grid.getRowEditor().startEditing(rowIndex);
        }

        var afterEdit = function (e) {
            
            e.grid.stopEditing();
            var payMethod = $("#<%= txtModeOfPayment.ClientID %>").val();
            
            EShop.WebServicee.UpdateOrder(e.record.data.OrderId, payMethod);
        };


        var categoryGrid;
        var paymentMethod_Renderer = function (value, p, record, rowIndex) {
            if (value == "CreditCard")
                return "card";
            else if (value == "bKash")
                return "bKash";
            else
                return "others";

        }



        var searchOrder = function (grid) {
            EShop.WebService.SearchOrder();
        }


        var onDocumentReady = function (grid, winDet) {
            categoryGrid = grid;

        }

       
    </script>
    <ext:ResourceManager ID="ScriptManager1" runat="server" Theme="Gray">
        <Listeners>
            <DocumentReady Fn="onDocumentReady(#{GridPanel1})" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="Store1" runat="server" RemoteSort="true" OnRefreshData="Store1_RefreshData">
        <AutoLoadParams>
            <ext:Parameter Name="sort" Value="OrderId desc" Mode="Value" />
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="100" Mode="Raw" />
        </AutoLoadParams>
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="OrderId">
                <Fields>
                    <ext:RecordField Name="OrderId" ServerMapping="OrderId" />
                    <ext:RecordField Name="OrderNumber" ServerMapping="OrderNumberPrefix" />
                    <ext:RecordField Name="CreateDate" ServerMapping="OrderDate" Type="Date" />
                    <ext:RecordField Name="SubTotal" ServerMapping="SubTotal" />
                     <ext:RecordField Name="TotalAmount" ServerMapping="TotalAmount"  />
                    <ext:RecordField Name="PaymentType" ServerMapping="PaymentType" />
                    <ext:RecordField Name="PurchaseById" ServerMapping="UserId" />
                    <ext:RecordField Name="BillingName" ServerMapping="Name" />
                    <ext:RecordField Name="BillingEmail" ServerMapping="EmailAddress" />
                    <ext:RecordField Name="SpecialInstruction" ServerMapping="SpecialInstruction" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <div class="admin-function-top inline">
        
        <ext:GridPanel ID="GridPanel1" runat="server" EnableViewState="true" AutoHeight="true"
            StoreID="Store1">
            <ColumnModel>
                <Columns>
                   <ext:Column Header="Order #" DataIndex="OrderId">
                        <Renderer Fn="OrderCode_Renderer" />
                    </ext:Column>
                     <ext:Column Header="Billing Name" DataIndex="BillingName" Align="Left"></ext:Column>
                     <ext:Column Header="Billing Email" DataIndex="BillingEmail" Align="Left"></ext:Column>
                    <ext:Column Header="Purchase Date" DataIndex="CreateDate" Align="Right">
                        <Renderer Fn="Date_Renderer" />
                    </ext:Column>
                    
                    <ext:Column Header="Order Amount" DataIndex="TotalAmount" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
             
                    <ext:Column Header="Payment Method" DataIndex="PaymentType" Align="Center">
                    <Renderer Fn="paymentMethod_Renderer" />
                    </ext:Column>
                       
                    <ext:CommandColumn DataIndex="SpecialInstruction">
                        <Commands>
                            <ext:GridCommand Icon="ApplicationEdit" CommandName="ManualAuth" Text="Authorize Payment" />
                        </Commands>
                        <Editor>
                            <ext:MultiField runat="server">
                                <Fields>
                                    <ext:Label ID="Label4" Text="Mode of payment accepted" runat="server" />
                                    <ext:TextField ID="txtModeOfPayment" runat="server" DataIndex="SpecialInstruction" />
                                </Fields>
                            </ext:MultiField>
                        </Editor>
                    </ext:CommandColumn>
                
      
                </Columns>
            </ColumnModel>
            <TopBar>
                <ext:Toolbar ID="SearchToolbar2" runat="server" AutoScroll="true">
                    <Items>
                            <ext:TextField ID="txtOrderNo" runat="server" EmptyText="Order#" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:TextField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer7" runat="server" Width="2px" />
                
                        <ext:DateField ID="txtDateFrom" runat="server" EmptyText="Date From" EnableKeyEvents="true">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:DateField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10px" />
                        <ext:DateField ID="txtDateTo" runat="server" EmptyText="Date To" EnableKeyEvents="true">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:DateField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" Width="10px" />
                        
                        <ext:Button ID="btnToolbarSearch" runat="server" Text="Search" Icon="Magnifier">
                            <Listeners>
                                <Click Handler="searchOrder(#{GridPanel1});" />
                            </Listeners>
                        </ext:Button>
                        
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="100" DisplayInfo="true"
                    DisplayMsg="Displaying orders {0} - {1} of {2}" EmptyMsg="No orders to display"
                    AutoWidth="true" />
            </BottomBar>
            <LoadMask ShowMask="true" />
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" ColumnPosition="7"
                    AllowDeselect="true" CheckOnly="true" />
            </SelectionModel>
            <Plugins>
                <ext:RowEditor ID="rowedi" runat="server" SaveText="Update" ClicksToEdit="2" ErrorSummary="false"
                    ShowTooltip="={Ext.emptyFn}">
                    <Listeners>
                        <AfterEdit Fn="afterEdit" />
                    </Listeners>
                </ext:RowEditor>
            </Plugins>
            <Listeners>
                <Command Handler="CommandHandler(command, rowIndex, this)" />
            </Listeners>
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true" />
            </View>
        </ext:GridPanel>
    </div>
    <script type="text/javascript">
        Ext.override(Ext.grid.GridView, {
            getEditorParent: function () {
                return document.body;
            }
        });
    </script>
</asp:Content>
